#include <stdio.h>
#include <string.h>

#define STDIN
#define DEBUG

int c[100][100];
char base_str[101];
int base_str_len;
char next_str[101];
int max_len = 0;

int t, n;

#ifdef DEBUG
void print_c()
{
	int ii, jj;
	for (ii = 0; ii < base_str_len; ++ii)
	{
		for (jj = 0; jj < base_str_len; ++jj)
		{
			printf("%d ", c[ii][jj]);
		}
		printf("\n");
	}
}
#endif

void process_base_str()
{
	base_str_len = strlen(base_str);

	int i, j;
	for (i = 0; i < base_str_len; ++i)
	{
		for (j = 0; j < base_str_len; ++j)
			c[i][j] = 1;
	}
	max_len = 0;
#ifdef DEBUG
	print_c();
#endif
}

void process_next_str(int no)
{
	char tmp1[101];
	char tmp2[101];

#ifdef DEBUG
	printf("%s\n", next_str);
#endif

	int i, j;
	for (i = 0; i < base_str_len; ++i)
	{
		for (j = 0; j <= i; ++j)
		{
			if (c[j][i] == no)
				continue;
			strncpy(tmp1, &base_str[j], i-j+1);
			tmp1[i-j+1] = '\0';
#ifdef DEBUG
			printf("%s\n", tmp1);
#endif
			if (strstr(next_str, tmp1) != NULL)
			{
				c[j][i]++;
				continue;
			}

			int k = i-j;
			while (k >= 0)
			{
				tmp2[i-j-k] = tmp1[k];
				k--;
			}
			tmp2[i-j+1] = '\0';
			if (strstr(next_str, tmp2) != NULL)
				c[j][i]++;

			if (max_len < c[j][i])
				max_len = c[j][i];

		}
	}

#ifdef DEBUG
	print_c();
#endif
}

int process_find_max()
{

	int i, j;
	for (i = base_str_len-1; i>= 0; i -= 1)
	{
		for (j = 0; j < base_str_len; j += 1)
		{
			if (j + i >= base_str_len)
				break;
			if (c[j][j+i] == n) 
				//如果在base_str[j:j+i]出现的次数恰好等于字符串的个数，那么就说明此字符串在所有字符串中都出现
				//它的长度为(j+i - j + 1) = (i+1)
				return i+1;

		}
	}

	return 0;
}

int main()
{
#ifdef STDIN
	freopen("bin/1226.in", "r", stdin);
#endif
	int i, j;

	scanf("%d", &t);

	for (i = 0; i < t; ++i)
	{
		scanf("%d", &n);
		scanf("%s", base_str);

		process_base_str();

		for (j = 1; j < n; ++j)
		{
			scanf("%s", next_str);
			process_next_str(j+1);
		}

		printf("%d\n", process_find_max());
	}
	return 0;
}
